#include "formsmode.h"
#include "ui_formsmode.h"
#include"student.h"
#include"admininfo.h"
#include"execsql.h"
#include"student_1.h"
#include<QDebug>
#include<QMessageBox>
//#include"student.h"

FormSMode::FormSMode(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FormSMode)
{
    ui->setupUi(this);
}

FormSMode::~FormSMode()
{
    delete ui;
}
void FormSMode::selectsuccess(QString id,QString pswd)
{
    ExecSQL exes;
     AdminInfo info_a = exes.selectAdminInfo(id);
     if(pswd == info_a.getPswd())
     {
       this->hide();
        info_a.display();
     }else
     {
         QMessageBox msgBox;
         msgBox.setText("Error: Your ID or Password !!");
         msgBox.setInformativeText("Please try again !");
         msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel);
         msgBox.setDefaultButton(QMessageBox::Retry);

         int ret = msgBox.exec();
         switch (ret) {
           case QMessageBox::Retry:
               ui->lineEdit_sid->setFocus();
               break;
           case QMessageBox::Cancel:
               this->close();
               break;
           default:
               // should never be reached
               break;
         qDebug()<<"fail : find people!!";
     }
   }
     m_id = id;
}

void FormSMode::showformSmode()
{
    emit signalformSmode();
    this->show();
}

void FormSMode::showSW()
{
    Student *sw = new Student;
    sw->show();
    sw->selectBoxSlot(str);
}

void FormSMode::slotStudent_1()
{
        t1W->show();
        t1W->str = str;
}

void FormSMode::on_pb_ok_clicked()
{
        t1W = new Student_1;
       connect(t1W,&Student_1::signalstudent_1,this,&FormSMode::slotStudent_1);
       selectsuccess(ui->lineEdit_sid->text(),ui->lineEdit_spswd->text());
       t1W->showstudent_1();
       t1W->selectBoxSlot(m_id);
}

void FormSMode::on_pb_cancle_clicked()
{
    this->hide();
    this->showSW();
}
